package com.cxhc.cockpit;


import com.cxhc.app.api.mapper.RpFeedbackMapStructMapper;
import com.cxhc.app.api.vo.RpFeedbackVo;
import com.cxhc.common.annotation.Anonymous;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.core.domain.R;
import com.cxhc.common.core.page.TableDataInfo;
import com.cxhc.system.domain.cockpit.RpFeedback;
import com.cxhc.system.service.cockpit.IRpFeedbackService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 事件统计接口
 */
@RestController()
@RequestMapping("/cockpit/event")
@ApiOperation("/cockpit/event")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ApiEvent extends BaseController {


    @Resource
    private IRpFeedbackService rpFeedbackService;

    /**
     * 事件统计
     *
     * @return
     */
    @Anonymous
    @RequestMapping("/eventNum")
    @ApiOperation("/eventNum")
    private R<Map<String,String>> eventNum() {
        return R.ok(rpFeedbackService.selectEventNum(null,null,null));
    }

    /**
     * 查询报修列表
     */
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody RpFeedbackVo rpFeedbackVo)
    {
        RpFeedback rpFeedback = RpFeedbackMapStructMapper.INSTANCE.RpFeedbackVoToRpFeedback(rpFeedbackVo);
        PageHelper.startPage(rpFeedbackVo.getPageNum(),rpFeedbackVo.getPageSize(),"AddTime desc");
        List<RpFeedback> list = rpFeedbackService.selectRpFeedbackListForCockpit(rpFeedback);
        return getDataTable(list);
    }

    /**
     * 获取报修详细信息
     */
    @GetMapping(value = "/details/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(rpFeedbackService.selectRpFeedbackByID(ID));
    }

}
